package com.luoluo.controller;

import com.luoluo.dao.LeaveWordMapper;
import com.luoluo.dao.TouristsLeaveWordMapper;
import com.luoluo.dao.UserLeaveWordMapper;
import com.luoluo.dao.UserTableMapper;
import com.luoluo.pojo.LeaveWord;
import com.luoluo.pojo.UserTable;
import com.luoluo.pojo.builder.LeaveWordBuilder;
import com.luoluo.pojo.builder.TouristsLeaveWordBuilder;
import com.luoluo.pojo.builder.UserLeaveWordBuilder;
import com.luoluo.pojo.builder.UserTableBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
public class HelloController {

    @ResponseBody
    @RequestMapping("hello")
    public String hello(@RequestParam(value = "name",defaultValue = "World")String name){
        return "Hello "+name+"!!!";
    }

    @RequestMapping("h")
    public String h(@RequestParam(value = "name",defaultValue = "World")String name, Model model){
        model.addAttribute("name",name);
        return "hello";
    }


    @Autowired
    LeaveWordMapper leaveWordMapper;
    @Autowired
    TouristsLeaveWordMapper touristsLeaveWordMapper;
    @Autowired
    UserLeaveWordMapper userLeaveWordMapper;
    @Autowired
    UserTableMapper userTableMapper;
    @ResponseBody
    @RequestMapping("adddata")
    public String all(){
//        for (int i = 0; i < 233; i++) {
//            Date date = new Date();
//            LeaveWord lw = new LeaveWordBuilder()
//                    .builderLeaveWord("留言内容" + i)
//                    .builderTime(date)
//                    .builderEffective(1)
//                    .build();
//            leaveWordMapper.insert(lw);
//            //游客
//            touristsLeaveWordMapper.insert(new TouristsLeaveWordBuilder()
//                    .builderLeaveWordId(lw.getId())
//                    .builderIp("127.0.0.1,"+i)
//                    .builderName("测试"+i)
//                    .builderEffective(1)
//            .build());
//        }
//        System.out.println("游客留言完成");
        for (int i = 0; i < 233; i++) {
            Date date = new Date();
            LeaveWord lw = new LeaveWordBuilder()
                    .builderLeaveWord("留言内容" + i)
                    .builderTime(date)
                    .builderEffective(1)
                    .build();
            leaveWordMapper.insert(lw);
            //用户
            UserTable userTable = new UserTableBuilder()
                    .setAccount("zhanghao"+i)
                    .setPassword("123")
                    .setEffective(1)
                    .setEmail(i+"ceshi@qq.com")
                    .setIp("127.0.0.1,"+i)
                    .setPhone("11012345"+i)
                    .setName("用户"+i)
                    .build();
            userTableMapper.insert(userTable);
            userLeaveWordMapper.insert(new UserLeaveWordBuilder()
                    .builderLeaveWordId(lw.getId())
                    .builderUserId(userTable.getId())
                    .build());
        }
        System.out.println("用户留言完成");
        return "OK!";
    }

}
